package study.transaction.jdbc.dao;

import cn.hutool.core.util.StrUtil;
import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class BaseDao {

    private static final String CONN_SQL = StrUtil.builder()
            .append(" SELECT connection_id(); ").toString();

    protected Connection connection;

    protected BaseDao(Connection connection) {
        this.connection = connection;
    }

    @SneakyThrows
    public String getConnId() {
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(CONN_SQL);
        String value = null;
        while (rs.next()) {
            value = rs.getString(1);
        }
        return value;
    }
}
